package net.jiastudy.core.utils;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import net.jiastudy.core.common.SecurityConstant;

public class JwtUtil {

	public static String makeToken(String username, Integer tokenExpireTime) {
		Map<String, Object> claims = new HashMap<>();
		claims.put(SecurityConstant.LOGIN_TIME, System.currentTimeMillis());
		String token = Jwts.builder()
				// 主题 放入用户名
				.setSubject(username).addClaims(claims)
				// 自定义属性 放入用户拥有权限
				// .claim(SecurityConstant.AUTHORITIES, JSON.toJSON(authorities))
				// 失效时间
				.setExpiration(new Date(System.currentTimeMillis() + tokenExpireTime * 60 * 1000))
				// 签名算法和密钥
				.signWith(SignatureAlgorithm.HS512, SecurityConstant.JWT_SIGN_KEY).compact();
		token = SecurityConstant.TOKEN_SPLIT + token;
		return token;
	}
}
